#ifndef __MARS_CORE_CRC_H__
#define __MARS_CORE_CRC_H__

namespace Core
{

extern uint32 g_CRCTable[];

class StrCRC
{
public:
	static uint32 CRC( const std::string& str );
};

inline uint32 StrCRC::CRC( const std::string& str )
{
	uint32 length = str.size();
	uint32 crc = 0xFFFFFFFF;
	for ( uint32 i = 0; i < length; i++ )
	{
		char c = str[i];
		uint32 cl = ( c & 255 );
		crc = ( crc << 8 ) ^ g_CRCTable[ ( crc >> 24 ) ^ cl ];
		uint32 ch = ( c >> 8 ) & 255;
		crc = ( crc << 8 ) ^ g_CRCTable[ ( crc >> 24 ) ^ ch ];
	}
	return ~crc;
}

} // end of namespace Core

#endif // end of #ifndef __MARS_CORE_CRC_H__